package com.augurit.common.common.http.kt.interceptor

import okhttp3.Interceptor
import okhttp3.Response

/**
 *  author : yanghaozhang
 *  date : 2022/5/4 20:51
 *  description :
 */
class HttpHandlerInterceptor(var mHandler: GlobalHttpHandler) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val originalResponse: Response = try {
            chain.proceed(mHandler.onHttpRequestBefore(chain, request))
        } catch (e: Exception) {
            throw e
        }
        //这里可以比客户端提前一步拿到服务器返回的结果,可以做一些操作,比如token超时,重新获取
        return mHandler.onHttpResultResponse(chain, originalResponse)
    }
}